package org.net.cms.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.net.cms.controller.admin.leave.vo.StudentLeaveReqVO;
import org.net.cms.controller.app.leave.vo.AppStudentLeaveReqVO;
import org.net.cms.controller.app.leave.vo.AppStudentLeaveRespVO;
import org.net.cms.dao.StudentLeaveDto;

import java.util.List;

@Mapper
public interface StudentLeaveMapper {

    @Select("SELECT * FROM student_leave WHERE id = #{id} AND deleted = 0")
    StudentLeaveDto findById(int id);

    @Select("select * from student_leave where parent_id = #{parentId} and deleted = 0")
    List<StudentLeaveDto> getAll(int parentId);

    @Insert("INSERT INTO student_leave (parent_id, student_id, phone, name, date, reason) " +
            "VALUES (#{parentId}, #{studentId}, #{phone}, #{name}, #{date}, #{reason})")
    int insert(StudentLeaveDto studentLeave);

    @Update("UPDATE student_leave " +
            "SET parent_id = #{parentId}, " +
            "    student_id = #{studentId}, " +
            "    phone = #{phone}, " +
            "    name = #{name}, " +
            "    date = #{date}, " +
            "    reason = #{reason} " +
            "WHERE id = #{id} AND deleted = 0")
    int updateLeave(AppStudentLeaveRespVO studentLeave);

    @Update("update student_leave set deleted = 1 where id = #{id}")
    int deleteLeave(int id);

    @Select("select * from student_leave where status = #{status} and deleted = 0")
    List<StudentLeaveDto> findAllByStatus(int status);

    @Update("update student_leave set status = #{status} where id = #{id}")
    int updateStatus(int id, int status);
}
